/*
SIT172 Assignment 3
Author :
Date :
Problem Description
You are working as an Engineer for a materials manufacturing research lab and have been asked
to provide an automated solution to analyse data.
The data relates to a new material being developed. The data is a measure of strength recorded
every 100mm of the material and is stored in a file.
Each line in the file represents a row of measurements on the material. Data is separated by a comma (,).
Determine the final-value for each row and column of the data.
Create and display a final-value map that represents the value for each row and column as
follows:
If the value for a cell in each row is less than the average for the row and column, display -1
If the value for a cell in each row is greater than the average for the row and column display 1,
otherwise display 0
Calculate and display the count for the values 1, 0 and -1 for each row and column
Test the sheet using the following rules to determine if the sheet is rejected or accepted.
Rule 1. If any count for a row or column is greater or equal to than 50% of the number of rows or
columns then that row or column is rejected.
Report the number of times the patterns are detected.
Where 50 or more of the patterns are identified the sheet of material is rejected.
Otherwise the sheet is accepted.
The manufacturing process samples 1 of every 10 sheets produced, therefore the analysis will be
undertaken as required and must be completed
in a timely manner to enable the process to be stopped, recalculated, then restarted.
*/
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
//#include <stdbool.h>
// Debug switch (‘1’ for debug ON, ‘0’ for debug OFF)
#define DEBUG 1
// Declared constants
// Name of file that stores our raw data
#define FILE_NAME “data-1.csv”
// Data size
#define MAX_ROWS 20
#define MAX_COLUMNS 20
//CONSTANT GREATER_THAN_CHAR = 1
const int GREATER_THAN_CHAR = 1;
//CONSTANT LESS_TAHN_CHAR = -1
const int LESS_THAN_CHAR = -1;
//CONSTANT NEITHER_CHAR = 0
const int NEITHER_CHAR = 0;
//CONSTANT MAX_CHARS = 3
#define MAX_CHARS 3
//CONSTANT TOLERANCE = 0.05
const double TOLERANCE = 0.05;
//CONSTANT RULE_1_HURDLE_PERCENT = 0.5
const double RULE_1_HURDLE_PERCENT = 0.5;
//CONSTANT RULE_2_HURDLE = 50
const int RULE_2_HURDLE = 50;
//CONSTANT PASSED_CHAR = ‘P’
const char PASSED_CHAR = ‘P’ ;
//CONSTANT INTERSECTION_PATTERN_CHAR = ‘I’
const char INTERSECTION_PATTERN_CHAR = ‘I’;
//CONSTANT ROW_PATTERN_CHAR = ‘R’
const char ROW_PATTERN_CHAR = ‘R’;
//CONSTANT COLUMN_PATTERN_CHAR = ‘C’
const char COLUMN_PATTERN_CHAR = ‘C’;
//load data from csv file
int loadData(float rawData[][MAX_COLUMNS]){
//’ Read the raw data from the data-1.csv file
// Misc variables used for reading the data from the file
float tempfloat = 0.0F;
char newline = ‘ ‘;
//INITIALISE rowIndex = 0
int rowIndex = 0;
//INITIALISE columnIndex = 0
int columnIndex = 0;
// Open the file for reading
FILE *infp;
infp = fopen(FILE_NAME, “r”);
// Check for errors and exit if found
if (infp == NULL)
{
printf(“Error: failed to open %s for readingn”, FILE_NAME);
return(1);
}
// Read the file into the data structure
for (rowIndex = 0; rowIndex < MAX_ROWS; rowIndex++)
{
// Read up until the last value
for (columnIndex = 0; columnIndex < MAX_COLUMNS – 1; columnIndex++)
{
if (fscanf(infp, “%f,”, &tempfloat) != EOF)
{
rawData[rowIndex][columnIndex] = tempfloat;
}
else
{
printf(“Error: incorrect file format at row %d, col %d.n”, rowIndex + 1, columnIndex + 1);
return(1);
}
}
// Read the last value and the newline char
if (fscanf(infp, “%f%c”, &tempfloat, &newline) != EOF)
{
// Check if the last character in the line was a n otherwise an error occured
if (newline != ‘